package com.nguyen.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nguyen.entities.DishItem;
import com.nguyen.letcook.R;
import com.nguyen.viewholders.DishItemViewHolder;

public class ListDishAdapter extends BaseAdapter {

	ArrayList<DishItem> arrDish = new ArrayList<DishItem>();
	LayoutInflater mInflater;
	
	public ListDishAdapter(Context context){
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public void clear(){
		arrDish.clear();
	}
	
	public void remove(DishItem item){
		arrDish.remove(item);
	}
	
	public void remove(int index){
		arrDish.remove(index);
	}
	
	@Override
	public int getCount() {
		
		return arrDish.size();
	}

	public void addItem(DishItem item){
		arrDish.add(item);
	}
	
	@Override
	public Object getItem(int position) {
		
		return null;
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DishItemViewHolder viewHolder;
		if(convertView == null){
			viewHolder = new DishItemViewHolder();
			convertView = mInflater.inflate(R.layout.dish_item, null);
			viewHolder.image 	= (ImageView)convertView.findViewById(R.id.imgDish);
			viewHolder.txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
			viewHolder.txtDesc 	= (TextView) convertView.findViewById(R.id.txtDescription);
			viewHolder.txtPrice = (TextView) convertView.findViewById(R.id.txtPrice);
			
			convertView.setTag(viewHolder);
		}
		else
			viewHolder = (DishItemViewHolder)convertView.getTag();
		
		viewHolder.txtTitle.setText(arrDish.get(position).getName());
		viewHolder.txtDesc.setText(arrDish.get(position).getDescription());
		viewHolder.txtPrice.setText("$" + arrDish.get(position).getPrice());
		return convertView;
	}

}
